<template>
  <div class="activated-page">
    <div class="title">粤歌学唱</div>
    
    <div class="main-button-container">
      <button class="start-learning-btn" @click="startLearning">
        <span class="btn-text-top">开始</span>
        <span class="btn-text-bottom">学歌</span>
      </button>
    </div>
    
    <!-- 更换微信对话框 -->
    <el-dialog
      v-model="changeWeChatVisible"
      :title="''"
      width="90%"
      :show-close="true"
      center
      class="custom-dialog"
    >
      <div class="dialog-content">
        <div class="dialog-text">请输入新微信的手机号</div>
        
        <div class="input-group">
          <input 
            type="tel" 
            class="dialog-input" 
            v-model="newPhone"
            placeholder="请输入新手机号"
            maxlength="11"
          />
        </div>
        
        <div class="input-group">
          <input 
            type="tel" 
            class="dialog-input" 
            v-model="confirmPhone"
            placeholder="请再输入一遍"
            maxlength="11"
          />
        </div>
      </div>
      
      <template #footer>
        <div class="dialog-footer">
          <button class="confirm-btn" @click="handleConfirmChange">确认修改</button>
        </div>
      </template>
    </el-dialog>
    
    <!-- 确认更换微信提示 -->
    <el-dialog
      v-model="confirmDialogVisible"
      :title="''"
      width="90%"
      :show-close="false"
      center
      class="custom-dialog confirm-dialog"
    >
      <div class="dialog-content">
        <div class="dialog-text warning-text">每年只能更换两次微信，确认要更换吗？</div>
      </div>
      
      <template #footer>
        <div class="dialog-footer double-btn">
          <button class="cancel-btn" @click="cancelChange">取消</button>
          <button class="confirm-btn" @click="submitChange">确认</button>
        </div>
      </template>
    </el-dialog>
    
    <!-- 更换成功后的提示 -->
    <el-dialog
      v-model="finalNoticeVisible"
      :title="''"
      width="90%"
      :show-close="false"
      center
      class="custom-dialog notice-dialog"
    >
      <div class="dialog-content">
        <div class="dialog-text instruction-text">请用新微信打开粤歌学唱小程序，用你刚刚输入的手机号进行激活</div>
      </div>
      
      <template #footer>
        <div class="dialog-footer">
          <button class="confirm-btn" @click="closeFinalNotice">我知道了</button>
        </div>
      </template>
    </el-dialog>
    
    <div class="menu-container">
      <div class="menu-item" @click="changeWechat">
        <div class="menu-icon wechat-icon">
          <el-icon><ChatDotSquare /></el-icon>
        </div>
        <div class="menu-text">更换微信</div>
        <div class="menu-arrow">
          <el-icon><ArrowRight /></el-icon>
        </div>
      </div>
      
      <div class="menu-item" @click="showTutorial">
        <div class="menu-icon tutorial-icon">
          <el-icon><Reading /></el-icon>
        </div>
        <div class="menu-text">使用教程</div>
        <div class="menu-arrow">
          <el-icon><ArrowRight /></el-icon>
        </div>
      </div>
      
      <div class="menu-item" @click="showSaveTool">
        <div class="menu-icon save-icon">
          <el-icon><Download /></el-icon>
        </div>
        <div class="menu-text">如何保存工具</div>
        <div class="menu-arrow">
          <el-icon><ArrowRight /></el-icon>
        </div>
      </div>
      
      <div class="menu-item" @click="requestSong">
        <div class="menu-icon request-icon">
          <el-icon><Document /></el-icon>
        </div>
        <div class="menu-text">求歌登记</div>
        <div class="menu-arrow">
          <el-icon><ArrowRight /></el-icon>
        </div>
      </div>
    </div>
    
    <div class="vip-info">
      <div class="vip-detail">VIP有效期: 2024-12-31 累计使用: 125天9小时</div>
    </div>
    
    <div class="customer-service" @click="contactCustomerService">
      <div class="service-icon">
        <el-icon><Headset /></el-icon>
      </div>
      <div class="service-text">联系客服</div>
    </div>
    <div class="service-hours">服务时间: 周一至周日 9:00-22:00</div>
  </div>
</template>

<script>
import { ref } from 'vue'
import { ChatDotSquare, Reading, Download, Document, ArrowRight, Headset } from '@element-plus/icons-vue'
import { useRouter } from 'vue-router'
import { ElMessage, ElDialog } from 'element-plus'

export default {
  name: 'ActivatedPage',
  components: {
    ChatDotSquare,
    Reading,
    Download,
    Document,
    ArrowRight,
    Headset,
    ElDialog
  },
  setup() {
    const router = useRouter()
    const changeWeChatVisible = ref(false)
    const confirmDialogVisible = ref(false)
    const finalNoticeVisible = ref(false)
    const newPhone = ref('')
    const confirmPhone = ref('')

    const startLearning = () => {
      console.log('开始学歌')
      // 设置为非免费试用模式
      localStorage.setItem('isFreeTrial', 'false')
      // 跳转到歌曲列表页面
      router.push('/songlist')
    }

    const changeWechat = () => {
      console.log('更换微信')
      // 显示更换微信对话框
      changeWeChatVisible.value = true
    }
    
    const validatePhone = (phone) => {
      const reg = /^1[3-9]\d{9}$/
      return reg.test(phone)
    }
    
    const handleConfirmChange = () => {
      // 验证手机号
      if (!validatePhone(newPhone.value)) {
        ElMessage({
          message: '请输入正确的手机号',
          type: 'warning',
          duration: 2000
        })
        return
      }
      
      // 验证两次输入是否一致
      if (newPhone.value !== confirmPhone.value) {
        ElMessage({
          message: '两次输入的手机号不一致',
          type: 'warning',
          duration: 2000
        })
        return
      }
      
      // 显示确认弹窗
      changeWeChatVisible.value = false
      confirmDialogVisible.value = true
    }
    
    // 取消更换操作
    const cancelChange = () => {
      confirmDialogVisible.value = false
      changeWeChatVisible.value = true
    }
    
    // 确认提交更改
    const submitChange = () => {
      // 关闭确认对话框，显示最终提示
      confirmDialogVisible.value = false
      finalNoticeVisible.value = true
    }
    
    // 关闭最终提示
    const closeFinalNotice = () => {
      // 提交更改
      ElMessage({
        message: '微信更换成功',
        type: 'success',
        duration: 2000
      })
      
      // 关闭对话框并清空输入
      finalNoticeVisible.value = false
      newPhone.value = ''
      confirmPhone.value = ''
    }

    const showTutorial = () => {
      console.log('显示使用教程')
      // 跳转到教程列表页面
      router.push('/tutorial-list')
    }

    const showSaveTool = () => {
      console.log('显示如何保存工具')
      // 显示保存工具的方法
    }

    const requestSong = () => {
      console.log('求歌登记')
      // 跳转到求歌登记页面
      router.push('/song-request')
    }

    const contactCustomerService = () => {
      console.log('联系客服')
      // 实现联系客服功能
    }

    return {
      startLearning,
      changeWechat,
      showTutorial,
      showSaveTool,
      requestSong,
      contactCustomerService,
      changeWeChatVisible,
      confirmDialogVisible,
      finalNoticeVisible,
      newPhone,
      confirmPhone,
      handleConfirmChange,
      cancelChange,
      submitChange,
      closeFinalNotice
    }
  }
}
</script>

<style scoped>
.activated-page {
  background: linear-gradient(135deg, #3d3878 0%, #1a1732 100%);
  color: white;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 20px;
}

.title {
  font-size: 24px;
  font-weight: bold;
  margin-top: 20px;
  margin-bottom: 40px;
}

.main-button-container {
  margin-bottom: 40px;
}

.start-learning-btn {
  width: 140px;
  height: 140px;
  border-radius: 50%;
  background: linear-gradient(135deg, #8A2BE2, #7B68EE);
  color: white;
  font-size: 18px;
  font-weight: bold;
  border: none;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 25px rgba(123, 104, 238, 0.7), 
              inset 0 0 15px rgba(255, 255, 255, 0.3),
              0 5px 15px rgba(0, 0, 0, 0.5);
  transition: all 0.3s ease;
  position: relative;
  overflow: hidden;
}

.btn-text-top, .btn-text-bottom {
  display: block;
  line-height: 1.2;
}

.btn-text-top {
  font-size: 20px;
  margin-bottom: 5px;
}

.btn-text-bottom {
  font-size: 22px;
}

.start-learning-btn:hover {
  transform: scale(1.05);
  box-shadow: 0 0 30px rgba(123, 104, 238, 0.8),
              inset 0 0 20px rgba(255, 255, 255, 0.4),
              0 8px 20px rgba(0, 0, 0, 0.6);
}

.start-learning-btn::before {
  content: "";
  position: absolute;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background: rgba(255, 255, 255, 0.1);
  transform: rotate(45deg);
  animation: shine 3s infinite;
  pointer-events: none;
}

@keyframes shine {
  0% {
    transform: translateX(-100%) translateY(-100%) rotate(45deg);
  }
  20%, 100% {
    transform: translateX(100%) translateY(100%) rotate(45deg);
  }
}

.menu-container {
  width: 100%;
  max-width: 400px;
  margin-bottom: 30px;
}

.menu-item {
  display: flex;
  align-items: center;
  padding: 15px;
  margin-bottom: 10px;
  border-radius: 10px;
  border: 1px solid #333;
  background-color: rgba(30, 30, 30, 0.6);
  cursor: pointer;
  transition: all 0.3s ease;
}

.menu-item:hover {
  background-color: rgba(40, 40, 40, 0.8);
  transform: translateX(3px);
}

.menu-icon {
  color: #7B68EE;
  font-size: 24px;
  margin-right: 15px;
  margin-top: 4px;
}

.menu-text {
  flex-grow: 1;
  font-size: 16px;
}

.menu-arrow {
  color: #666;
}

.vip-info {
  margin-top: auto;
  font-size: 12px;
  color: #666;
  text-align: center;
  margin-bottom: 30px;
}

.customer-service {
  display: flex;
  align-items: center;
  justify-content: center;
  color: #7B68EE;
  margin-bottom: 5px;
  cursor: pointer;
  transition: color 0.3s ease;
}

.customer-service:hover {
  color: #9370DB;
}

.service-icon {
  margin-right: 5px;
}

.service-hours {
  font-size: 12px;
  color: #666;
  text-align: center;
  margin-bottom: 20px;
}

/* 对话框样式 */
:deep(.el-dialog) {
  background-color: #1a1a2e;
  border-radius: 12px;
  border: 1px solid rgba(139, 92, 246, 0.3);
  box-shadow: 0 0 30px rgba(0, 0, 0, 0.6);
}

:deep(.el-dialog__header) {
  padding: 10px;
  text-align: center;
}

:deep(.el-dialog__title) {
  color: white;
  font-weight: 600;
  font-size: 18px;
}

:deep(.el-dialog__headerbtn .el-dialog__close) {
  color: rgba(255, 255, 255, 0.7);
}

:deep(.el-dialog__body) {
  padding: 24px;
  color: white;
}

:deep(.el-dialog__footer) {
  padding: 16px 24px 24px;
  border-top: none;
}

.dialog-content {
  padding-bottom: 10px;
}

.dialog-text {
  margin-bottom: 20px;
  text-align: center;
  color: rgba(255, 255, 255, 0.9);
  font-size: 16px;
}

.input-group {
  margin-bottom: 16px;
}

.dialog-input {
  width: 100%;
  height: 50px;
  background-color: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 10px;
  color: white;
  padding: 0 15px;
  font-size: 16px;
  outline: none;
  transition: border-color 0.3s;
}

.dialog-input:focus {
  border-color: #7B68EE;
}

.dialog-input::placeholder {
  color: rgba(255, 255, 255, 0.5);
}

.dialog-footer {
  display: flex;
  justify-content: center;
}

.confirm-btn {
  width: 100%;
  height: 50px;
  background: linear-gradient(135deg, #8A2BE2, #7B68EE);
  border: none;
  border-radius: 10px;
  color: white;
  font-size: 16px;
  font-weight: bold;
  cursor: pointer;
  transition: all 0.3s ease;
}

.confirm-btn:hover {
  box-shadow: 0 0 15px rgba(123, 104, 238, 0.7);
  transform: translateY(-2px);
}

.double-btn {
  display: flex;
  gap: 12px;
}

.double-btn .confirm-btn, .double-btn .cancel-btn {
  flex: 1;
  height: 45px;
}

.cancel-btn {
  background: rgba(255, 255, 255, 0.15);
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 10px;
  color: white;
  font-size: 16px;
  font-weight: bold;
  cursor: pointer;
  transition: all 0.3s ease;
}

.cancel-btn:hover {
  background: rgba(255, 255, 255, 0.2);
}

.warning-text {
  color: #FFB74D;
  font-weight: 500;
}

.instruction-text {
  color: #81C784;
  font-weight: 500;
  line-height: 1.6;
}

/* 响应式设计 */
@media (max-width: 480px) {
  .title {
    font-size: 22px;
    margin-top: 15px;
    margin-bottom: 30px;
  }
  
  .start-learning-btn {
    width: 120px;
    height: 120px;
  }
  
  .btn-text-top {
    font-size: 18px;
  }
  
  .btn-text-bottom {
    font-size: 20px;
  }
  
  .menu-container {
    width: 90%;
  }
  
  .menu-item {
    padding: 12px;
  }
  
  .vip-info {
    margin-bottom: 20px;
    font-size: 11px;
  }
}

@media (min-width: 768px) {
  .menu-container {
    max-width: 500px;
  }
  
  .menu-item {
    padding: 18px;
  }
  
  .title {
    font-size: 28px;
    margin-bottom: 50px;
  }
}
</style> 